function [irfstr, vardecomp] = irfselec(shockcheck,irf)
%Picks irf to structural shocks and according forcast error variance
%decomposition.

[nshocks, n_str_shocks]=size(shockcheck);
nvars=size(irf,1);

%Compute total variance
for var=1:nvars
    totvariance(var,:)=sum(cumsum(irf(var,:,:).^2,3),2);
end

nostrshock=n_str_shocks;

for shock=1:nshocks;
%%%%%% Attributes no identified shocks to "structural" shocks, n_str_shocks +1, +2,...    
  if max(shockcheck(shock,:))==0
      nostrshock=nostrshock+1;
%       strerr(nostrshock,:)=errstr(shock,:);
         for var=1:nvars
                irfstr(var,nostrshock,:)=irf(var,shock,:);
                vardecomp(var,nostrshock,:)=squeeze(cumsum(...
                    irfstr(var,nostrshock,:).^2,3))./squeeze(totvariance(var,:))';
         end
  else
    for str_shock=1:n_str_shocks   
        if shockcheck(shock,str_shock)==1
            for var=1:nvars
                irfstr(var,str_shock,:)=irf(var,shock,:);
                vardecomp(var,str_shock,:)=squeeze(cumsum(...
                    irfstr(var,str_shock,:).^2,3))./squeeze(totvariance(var,:))';
            end
        end
    end
  end
end
 
         